#ifndef __CANFD_CONFIG_H__
#define __CANFD_CONFIG_H__
#include "canfd_test.h"

void config_canfd_level_quality(void *param) {
    struct canfd_param_t *pparam = param;
    uint8_t i = 0;

    if (pparam->read_cnt == 0)
        pparam->read_cnt = 1;
    if (pparam->write_cnt == 0)
        pparam->write_cnt = 1;

    pparam->en_read = 1;
    pparam->read_cnt = -1;
    pparam->en_write = 1;
    pparam->write_cnt = -1;
    pparam->delay_ms = 5;

    for (i = 0; i < pparam->dev_num; i++) {
        pparam->dev[i].index = i;

        if (pparam->dev[i].msg_type_cnt == 0)
            pparam->dev[i].msg_type_cnt = 1;

        if (pparam->dev[i].baud_rate_cnt == 0) {
            pparam->dev[i].baud_rate_cnt = 1;

            pparam->dev[i].arbitration_baud[0].bitrate = 1000000;
            pparam->dev[i].arbitration_baud[0].sample_point = 800;
            pparam->dev[i].arbitration_baud[0].sjw = 4;
            pparam->dev[i].data_baud_rate[0].bitrate = 500000;
            pparam->dev[i].data_baud_rate[0].sample_point = 800;
            pparam->dev[i].data_baud_rate[0].sjw = 8;

            pparam->dev[i].arbitration_baud[1].bitrate = 1000000;
            pparam->dev[i].arbitration_baud[1].sample_point = 800;
            pparam->dev[i].arbitration_baud[1].sjw = 8;
            pparam->dev[i].data_baud_rate[1].bitrate = 1000000;
            pparam->dev[i].data_baud_rate[1].sample_point = 800;
            pparam->dev[i].data_baud_rate[1].sjw = 8;

            pparam->dev[i].arbitration_baud[2].bitrate = 1000000;
            pparam->dev[i].arbitration_baud[2].sample_point = 800;
            pparam->dev[i].arbitration_baud[2].sjw = 8;
            pparam->dev[i].data_baud_rate[2].bitrate = 2000000;
            pparam->dev[i].data_baud_rate[2].sample_point = 800;
            pparam->dev[i].data_baud_rate[2].sjw = 4;

            pparam->dev[i].arbitration_baud[3].bitrate = 1000000;
            pparam->dev[i].arbitration_baud[3].sample_point = 800;
            pparam->dev[i].arbitration_baud[3].sjw = 8;
            pparam->dev[i].data_baud_rate[3].bitrate = 4000000;
            pparam->dev[i].data_baud_rate[3].sample_point = 800;
            pparam->dev[i].data_baud_rate[3].sjw = 2;

            pparam->dev[i].arbitration_baud[4].bitrate = 1000000;
            pparam->dev[i].arbitration_baud[4].sample_point = 800;
            pparam->dev[i].arbitration_baud[4].sjw = 8;
            pparam->dev[i].data_baud_rate[4].bitrate = 5000000;
            pparam->dev[i].data_baud_rate[4].sample_point = 750;
            pparam->dev[i].data_baud_rate[4].sjw = 2;
        }

        pparam->dev[i].msg_type_cnt = 1;
        pparam->dev[i].msg[0] = (struct canfd_msg_t){
            .fmt = 1,
            .rtr = 0,
            .id = 0x15A5A5A5,
            .dlc = 64,
            .flg = 1,
            .data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, \
                     0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, \
                     0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, \
                     0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, \
                     0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, \
                     0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, \
                     0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, \
                     0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40}
        };
        // pparam->dev[i].msg[0] = (struct canfd_msg_t){
        //     .fmt = 1,
        //     .rtr = 0,
        //     .id = 0x15A5A5A5,
        //     .dlc = 8,
        //     .flg = 1,
        //     .data = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}
        // };
        pparam->dev[i].msg[1] = (struct canfd_msg_t){
            .fmt = 1,
            .rtr = 0,
            .id = 0x1A5A5A5A,
            .dlc = 8,
            .flg = 1,
            .data = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55}
        };
        pparam->dev[i].msg[2] = (struct canfd_msg_t){
            .fmt = 0,
            .rtr = 0,
            .id = 0x75A,
            .dlc = 8,
            .flg = 1,
            .data = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}
        };
    }
}

#endif /* __CANFD_CONFIG_H__ */
